﻿@page "/Maps/World"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore.Geo;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Drawing.Geometries

<GeoMap
    Series="@series"
    MapProjection="LiveChartsCore.Geo.MapProjection.Mercator">
</GeoMap>

@code {
    private HeatLand[] lands = new HeatLand[]
    {
        new() { Name = "bra", Value = 13 },
        new() { Name = "mex", Value = 10 },
        new() { Name = "usa", Value = 15 },
        new() { Name = "can", Value = 8 },
        new() { Name = "ind", Value = 12 },
        new() { Name = "deu", Value = 13 },
        new() { Name= "jpn", Value = 15 },
        new() { Name = "chn", Value = 14 },
        new() { Name = "rus", Value = 11 },
        new() { Name = "fra", Value = 8 },
        new() { Name = "esp", Value = 7 },
        new() { Name = "kor", Value = 10 },
        new() { Name = "zaf", Value = 12 },
        new() { Name = "are", Value = 13 }
    };
    private HeatLandSeries[] series;

    protected override void OnInitialized()
    {
        series = new HeatLandSeries[]
        {
            new HeatLandSeries { Lands = lands }
        };
        _ = DoRandomChanges(series[0]);
    }

    private async Task DoRandomChanges(HeatLandSeries series)
    {
        var r = new Random();
        await Task.Delay(1000);
        while (true)
        {
            foreach (var shape in series.Lands ?? Enumerable.Empty<IWeigthedMapLand>())
            {
                shape.Value = r.Next(0, 20);
            }
            await Task.Delay(500);
        }
    }
}
